home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / misc1s.zoo / misc1 / combine / vos.c < prev   
Encoding:
C/C++ Source or Header  |  1989-06-23  |  3.2 KB  |  188 lines

  1. #include "blu.h"
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include "util.h"
  5. #include "os_dep.h"
  6.  
  7. #define IO_ERR                 000400000
  8.  
  9. #define READ                 001
  10. #define WRITE                002
  11. #define BIN_READ             003
  12. #define BIN_WRITE            004
  13. #define CLOSE                014
  14. #define WRITEEOF             012
  15. #define WRITE_EOF            012
  16. #define OPEN                 013
  17. #define SETCRA               023
  18. #define DUMP_BUFFER          024
  19. #define FLUSH                037
  20. /*
  21.  *
  22.  * os_dep_file_pos -- Return current position in file
  23.  *
  24.  * This routine returns the current position in the file. The value
  25.  * returned is suitable for passing to os_dep_file_seek and is suitable
  26.  * for no other purpose.
  27.  *
  28.  * Return value:
  29.  *   Current position in the file.
  30.  *
  31.  */
  32.  
  33. rfa_type os_dep_file_pos (fp)
  34. FILE * fp;
  35. {
  36.  
  37.     return (fp -> cra);
  38. }
  39.  
  40. /*
  41.  *
  42.  * os_dep_file_read -- Read a record from a file.
  43.  *
  44.  * This routine reads a record from a file.
  45.  *
  46.  * Return value:
  47.  *   SS_NORMAL      Operation performed as requested.
  48.  *   SS_EOT         End of disk area reached
  49.  *   SS_READ_ERR    Error on read operation.
  50.  *   SS_SEEK_ERR    Seek error occured
  51.  *
  52.  */
  53.  
  54. STS_type os_dep_file_read (fp,
  55.     buf_ptr,
  56.     buf_len,
  57.     ret_len_ptr)
  58. FILE * fp;
  59. char   *buf_ptr;
  60. int     buf_len;
  61.  
  62. int    *ret_len_ptr;        /* output */
  63.  /* Returns the number of bytes read. */
  64.  /* A value of -1 indicates that an EOF record was read */
  65.  
  66. {
  67.  
  68.     STS_type status;
  69.  
  70.     int     i;
  71.  
  72.     fortran int     LOWREAD ();
  73.  
  74.  
  75.  
  76.     if (!fp -> symbolic) {
  77.         status = $IOW (LFN (fp), BIN_READ, (buf_len + 2) / 3, buf_ptr);
  78.         fp -> cra = C_Ereg ();
  79.         if (status & IO_ERR) {
  80.             return (SS_READ_ERR);
  81.         }
  82.     } else {
  83.  
  84.         i = (buf_len + 2) / 3;
  85.         status = LOWREAD (&(LFN (fp)), (int *) buf_ptr, &i);
  86.  
  87.         if (status <= -2) {
  88.             if (status == -2) {
  89.                 return (SS_EOT);
  90.             } else {
  91.                 return (SS_READ_ERR);
  92.             }
  93.         }
  94.  
  95.         *ret_len_ptr = status;
  96.         ++(fp -> cra);
  97.  
  98.     }
  99.  
  100.     return (SS_NORMAL);
  101.  
  102. }
  103.  
  104. /*
  105.  *
  106.  * os_dep_file_seek -- Seek to record within file
  107.  *
  108.  * This routine seek to a particular record within a file.
  109.  *
  110.  * Return value:
  111.  *   SS_NORMAL      Operation performed as requested.
  112.  *   SS_SEEK_ERR    Error on seek operation.
  113.  *
  114.  */
  115.  
  116. STS_type os_dep_file_seek (fp, rec_num)
  117. FILE * fp;
  118. rfa_type rec_num;
  119.  
  120. {
  121.  
  122.     STS_type status;
  123.  
  124.  
  125.  
  126.     if (rec_num >= 0 && fp -> cra != rec_num) {
  127.         status = $IOW (LFN (fp), SETCRA, rec_num, 0);
  128.         fp -> cra = C_Ereg ();
  129.         if (status & IO_ERR) {
  130.             return (SS_SEEK_ERR);
  131.         }
  132.     }
  133.     return (SS_NORMAL);
  134.  
  135. }
  136.  
  137. /*
  138.  *
  139.  * os_dep_file_write -- Write a record to a file.
  140.  *
  141.  * This routine writes a record to a file.
  142.  *
  143.  * Return value:
  144.  *   SS_NORMAL      Operation performed as requested.
  145.  *   SS_WRITE_ERR   Error on write operation.
  146.  *
  147.  */
  148.  
  149. STS_type os_dep_file_write (fp,
  150.     buf_ptr,
  151.     buf_len)
  152. FILE * fp;
  153. char   *buf_ptr;
  154. int     buf_len;        /* buffer length in bytes */
  155.  
  156. {
  157.  
  158.     STS_type status;
  159.  
  160.  
  161.  
  162.     if (buf_len <= 0) {
  163.         if (buf_len < 0) {
  164.             return (os_dep_file_write_eof (fp));
  165.         }
  166.         buf_len = 1;
  167.     }
  168.  
  169.     if (!fp -> symbolic) {
  170.         status = $IOW (LFN (fp), BIN_WRITE, (buf_len + 2) / 3, buf_ptr);
  171.     } else {
  172.  
  173.         buf_ptr[buf_len] = ' ';
  174.         buf_ptr[buf_len + 1] = ' ';
  175.         status = $IOW (LFN (fp), 02, (buf_len + 2) / 3, buf_ptr);
  176.  
  177.     }
  178.  
  179.     fp -> cra = C_Ereg ();
  180.  
  181.     if (status & IO_ERR) {
  182.         return (SS_WRITE_ERR);
  183.     }
  184.  
  185.     return (SS_NORMAL);
  186.  
  187. }
  188.